package com.example.eurekaserverclient.gclconverter;

public class UnifyResponse {
    public static final int DEFAULT_OK_CODE = 200;
    public static final int DEFAULT_ERROR_CODE = 500;

    private Integer code;
    private Object result;
    private String message;

    public UnifyResponse(Object result) {
        this.code = DEFAULT_OK_CODE;
        this.result = result;
    }

    public UnifyResponse(int code, String message, Object result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public UnifyResponse(CodeException e) {
        this.code = e.getCode();
        this.message = e.getMessage();
    }

    public UnifyResponse(Throwable e) {
        this.code = DEFAULT_ERROR_CODE;
        this.message = e.getMessage();
    }

    private UnifyResponse(int code) {
        this.code = code;
    }
    private UnifyResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static UnifyResponse OK = new UnifyResponse(DEFAULT_OK_CODE);
    public static UnifyResponse SERVER_ERROR = new UnifyResponse(500, "server error");
    public static UnifyResponse NOT_FOUND = new UnifyResponse(404, "not found");
    public static UnifyResponse BAD_REQUEST = new UnifyResponse(400, "bad request");
    public static UnifyResponse INVALID_PARAMETERS = new UnifyResponse(400, "参数不合法");

    public static UnifyResponse invalidParameter(String reason) {
        return new UnifyResponse(400, "参数不合法: " + reason);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
